#include "Map.cpp"


void BFSForGraphMap(GraphMap g,int v0) {
    queue<int> Q;
    bool visited[g->vexnum+1];
    for (int i = 0; i < g->vexnum+1; ++i) {
        visited[i] = false;
    }
    initQueue(Q);
    enterQueue(Q, v0);
    visited[v0] = true;
    visit(v0);
    while(!EmptyQueue(Q)) {
        int v;
        deleteQueue(Q, &v);
        int w = FirstAdjVertex(g,v);
        while (w != -1) {
            if (!visited[w]) {
                visit(w);
                visited[w] = true;
                enterQueue(Q, w);
            }
            w = NextAdjVertex(g,v,w);
        }
    }
}



void BFSForGraph(Graph g,int v0) {
    queue<int> s;
    bool visited[g->vexnum+1];
    for (int i = 0; i < g->vexnum+1; ++i) {
        visited[i] = false;
    }
    initQueue(s);
    enterQueue(s,v0);

    visited[v0] = true;
    visit(v0);
    while(!EmptyQueue(s)) {
        int v;
        deleteQueue(s,&v);
        ArcNode* p = g->vertex[v]->firstArc;
        while (p != NULL) {
            if (!visited[p->adj]) {
                visit(p->adj);
                visited[p->adj] = true;
                enterQueue(s, p->adj);
            }
            p = p->next;
        }
    }
}

int main(void){
//    Graph g = CreateGraphByFile("Map.txt");
//    BFSForGraph(g,2);
    GraphMap g2 = CreateGraphMapByFile("Map.txt");
    BFSForGraphMap(g2,3);
    return 0;
}